<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>sgp4oo: Fichero Fuente sgp4_date.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generado por Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Página&nbsp;principal</span></a></li>
      <li><a href="annotated.html"><span>Clases</span></a></li>
      <li class="current"><a href="files.html"><span>Archivos</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>Lista&nbsp;de&nbsp;archivos</span></a></li>
      <li><a href="globals.html"><span>Miembros&nbsp;de&nbsp;los&nbsp;ficheros</span></a></li>
    </ul>
  </div>
<h1>sgp4_date.cpp</h1><a href="sgp4__date_8cpp.html">Ir a la documentación de este archivo.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;<a class="code" href="sgp4__date_8h.html">sgp4_date.h</a>&quot;</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 
<a name="l00082"></a>00082 <span class="keywordtype">void</span>    <a class="code" href="classsgp4__date.html#a3c1affde9b5a9badeec11f39f0fe1552" title="this file contains extra routines needed for the main test program for sgp4.">sgp4_date::jday</a>
<a name="l00083"></a><a class="code" href="classsgp4__date.html#a3c1affde9b5a9badeec11f39f0fe1552">00083</a>         (
<a name="l00084"></a>00084           <span class="keywordtype">int</span> year, <span class="keywordtype">int</span> mon, <span class="keywordtype">int</span> day, <span class="keywordtype">int</span> hr, <span class="keywordtype">int</span> minute, <span class="keywordtype">double</span> sec,
<a name="l00085"></a>00085           <span class="keywordtype">double</span>&amp; jd
<a name="l00086"></a>00086         )
<a name="l00087"></a>00087    {
<a name="l00088"></a>00088      jd = 367.0 * year -
<a name="l00089"></a>00089           floor((7 * (year + floor((mon + 9) / 12.0))) * 0.25) +
<a name="l00090"></a>00090           floor( 275 * mon / 9.0 ) +
<a name="l00091"></a>00091           day + 1721013.5 +
<a name="l00092"></a>00092           ((sec / 60.0 + minute) / 60.0 + hr) / 24.0;  <span class="comment">// ut in days</span>
<a name="l00093"></a>00093           <span class="comment">// - 0.5*sgn(100.0*year + mon - 190002.5) + 0.5;</span>
<a name="l00094"></a>00094    }  <span class="comment">// end jday</span>
<a name="l00095"></a>00095 
<a name="l00154"></a>00154 <span class="keywordtype">void</span>    <a class="code" href="classsgp4__date.html#a270e3d9269bc498a33fef618016e6d79" title="this procedure converts the day of the year, days, to the equivalent month day, hour...">sgp4_date::days2mdhms</a>
<a name="l00155"></a><a class="code" href="classsgp4__date.html#a270e3d9269bc498a33fef618016e6d79">00155</a>         (
<a name="l00156"></a>00156           <span class="keywordtype">int</span> year, <span class="keywordtype">double</span> days,
<a name="l00157"></a>00157           <span class="keywordtype">int</span>&amp; mon, <span class="keywordtype">int</span>&amp; day, <span class="keywordtype">int</span>&amp; hr, <span class="keywordtype">int</span>&amp; minute, <span class="keywordtype">double</span>&amp; sec
<a name="l00158"></a>00158         )
<a name="l00159"></a>00159    {
<a name="l00160"></a>00160      <span class="keywordtype">int</span> i, inttemp, dayofyr;
<a name="l00161"></a>00161      <span class="keywordtype">double</span>    temp;
<a name="l00162"></a>00162      <span class="keywordtype">int</span> lmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
<a name="l00163"></a>00163 
<a name="l00164"></a>00164      dayofyr = (int)floor(days);
<a name="l00165"></a>00165      <span class="comment">/* ----------------- find month and day of month ---------------- */</span>
<a name="l00166"></a>00166      <span class="keywordflow">if</span> ( (year % 4) == 0 )
<a name="l00167"></a>00167        lmonth[1] = 29;
<a name="l00168"></a>00168      i = 1;
<a name="l00169"></a>00169      inttemp = 0;
<a name="l00170"></a>00170      <span class="keywordflow">while</span> ((dayofyr &gt; inttemp + lmonth[i-1]) &amp;&amp; (i &lt; 12))
<a name="l00171"></a>00171      {
<a name="l00172"></a>00172        inttemp = inttemp + lmonth[i-1];
<a name="l00173"></a>00173        i++;
<a name="l00174"></a>00174      }
<a name="l00175"></a>00175      mon = i;
<a name="l00176"></a>00176      day = dayofyr - inttemp;
<a name="l00177"></a>00177 
<a name="l00178"></a>00178      <span class="comment">/* ----------------- find hours minutes and seconds ------------- */</span>
<a name="l00179"></a>00179      temp = (days - dayofyr) * 24.0;
<a name="l00180"></a>00180      hr   = (int)floor(temp);
<a name="l00181"></a>00181      temp = (temp - hr) * 60.0;
<a name="l00182"></a>00182      minute  = (int)floor(temp);
<a name="l00183"></a>00183      sec  = (temp - minute) * 60.0;
<a name="l00184"></a>00184    }  <span class="comment">// end days2mdhms</span>
<a name="l00185"></a>00185 
<a name="l00247"></a>00247 <span class="keywordtype">void</span>    <a class="code" href="classsgp4__date.html#a8bd260e36fb647c9ff8f1c9eefe12f6a" title="this procedure finds the year, month, day, hour, minute and second given the julian...">sgp4_date::invjday</a>
<a name="l00248"></a><a class="code" href="classsgp4__date.html#a8bd260e36fb647c9ff8f1c9eefe12f6a">00248</a>         (
<a name="l00249"></a>00249           <span class="keywordtype">double</span> jd,
<a name="l00250"></a>00250           <span class="keywordtype">int</span>&amp; year, <span class="keywordtype">int</span>&amp; mon, <span class="keywordtype">int</span>&amp; day,
<a name="l00251"></a>00251           <span class="keywordtype">int</span>&amp; hr, <span class="keywordtype">int</span>&amp; minute, <span class="keywordtype">double</span>&amp; sec
<a name="l00252"></a>00252         )
<a name="l00253"></a>00253    {
<a name="l00254"></a>00254      <span class="keywordtype">int</span> leapyrs;
<a name="l00255"></a>00255      <span class="keywordtype">double</span>    days, tu, temp;
<a name="l00256"></a>00256 
<a name="l00257"></a>00257      <span class="comment">/* --------------- find year and days of the year --------------- */</span>
<a name="l00258"></a>00258      temp    = jd - 2415019.5;
<a name="l00259"></a>00259      tu      = temp / 365.25;
<a name="l00260"></a>00260      year    = 1900 + (int)floor(tu);
<a name="l00261"></a>00261      leapyrs = (int)floor((year - 1901) * 0.25);
<a name="l00262"></a>00262 
<a name="l00263"></a>00263      <span class="comment">// optional nudge by 8.64x10-7 sec to get even outputs</span>
<a name="l00264"></a>00264      days    = temp - ((year - 1900) * 365.0 + leapyrs) + 0.00000000001;
<a name="l00265"></a>00265 
<a name="l00266"></a>00266      <span class="comment">/* ------------ check for case of beginning of a year ----------- */</span>
<a name="l00267"></a>00267      <span class="keywordflow">if</span> (days &lt; 1.0)
<a name="l00268"></a>00268        {
<a name="l00269"></a>00269          year    = year - 1;
<a name="l00270"></a>00270          leapyrs = (int)floor((year - 1901) * 0.25);
<a name="l00271"></a>00271          days    = temp - ((year - 1900) * 365.0 + leapyrs);
<a name="l00272"></a>00272        }
<a name="l00273"></a>00273 
<a name="l00274"></a>00274      <span class="comment">/* ----------------- find remaing data  ------------------------- */</span>
<a name="l00275"></a>00275      days2mdhms(year, days, mon, day, hr, minute, sec);
<a name="l00276"></a>00276      sec = sec - 0.00000086400;
<a name="l00277"></a>00277    }  <span class="comment">// end invjday</span>
<a name="l00278"></a>00278 
<a name="l00279"></a>00279 
<a name="l00280"></a>00280 <span class="comment">/* -----------------------------------------------------------------------------</span>
<a name="l00281"></a>00281 <span class="comment">*  @brief   this function finds the greenwich sidereal time.</span>
<a name="l00282"></a>00282 <span class="comment">*    @param   jdut1        - julian date in ut1             days from 4713 bc</span>
<a name="l00283"></a>00283 <span class="comment">*    @param   gstime      output- greenwich sidereal time        0 to 2pi rad</span>
<a name="l00284"></a>00284 <span class="comment">*    @author  david vallado</span>
<a name="l00285"></a>00285 <span class="comment">*</span>
<a name="l00286"></a>00286 <span class="comment">*                           function gstime</span>
<a name="l00287"></a>00287 <span class="comment">*</span>
<a name="l00288"></a>00288 <span class="comment">*  this function finds the greenwich sidereal time.</span>
<a name="l00289"></a>00289 <span class="comment">*</span>
<a name="l00290"></a>00290 <span class="comment">*  author        : david vallado                  719-573-2600    1 mar 2001</span>
<a name="l00291"></a>00291 <span class="comment">*</span>
<a name="l00292"></a>00292 <span class="comment">*  inputs          description                    range / units</span>
<a name="l00293"></a>00293 <span class="comment">*    jdut1       - julian date in ut1             days from 4713 bc</span>
<a name="l00294"></a>00294 <span class="comment">*</span>
<a name="l00295"></a>00295 <span class="comment">*  outputs       :</span>
<a name="l00296"></a>00296 <span class="comment">*    gstime      - greenwich sidereal time        0 to 2pi rad</span>
<a name="l00297"></a>00297 <span class="comment">*</span>
<a name="l00298"></a>00298 <span class="comment">*  locals        :</span>
<a name="l00299"></a>00299 <span class="comment">*    temp        - temporary variable for doubles   rad</span>
<a name="l00300"></a>00300 <span class="comment">*    tut1        - julian centuries from the</span>
<a name="l00301"></a>00301 <span class="comment">*                  jan 1, 2000 12 h epoch (ut1)</span>
<a name="l00302"></a>00302 <span class="comment">*</span>
<a name="l00303"></a>00303 <span class="comment">*  coupling      :</span>
<a name="l00304"></a>00304 <span class="comment">*    none</span>
<a name="l00305"></a>00305 <span class="comment">*</span>
<a name="l00306"></a>00306 <span class="comment">*  references    :</span>
<a name="l00307"></a>00307 <span class="comment">*    vallado       2004, 191, eq 3-45</span>
<a name="l00308"></a>00308 <span class="comment">* --------------------------------------------------------------------------- */</span>
<a name="l00309"></a>00309 
<a name="l00315"></a>00315 <span class="keywordtype">double</span>  <a class="code" href="classsgp4__date.html#a9f5ce9d110c4cbadb06c9bfeaef28e91" title="Esta función devuelve la posición angular del tiempo sidéreo de Greenwich a través...">sgp4_date::gstime</a>
<a name="l00316"></a><a class="code" href="classsgp4__date.html#a9f5ce9d110c4cbadb06c9bfeaef28e91">00316</a>         (
<a name="l00317"></a>00317           <span class="keywordtype">double</span> jdut1
<a name="l00318"></a>00318         )
<a name="l00319"></a>00319    {
<a name="l00320"></a>00320      <span class="keyword">const</span> <span class="keywordtype">double</span> twopi = 2.0 * <a class="code" href="sgp4__math_8h.html#a1daf785e3f68d293c7caa1c756d5cb74">pi</a>;
<a name="l00321"></a>00321      <span class="keyword">const</span> <span class="keywordtype">double</span> deg2rad = <a class="code" href="sgp4__math_8h.html#a1daf785e3f68d293c7caa1c756d5cb74">pi</a> / 180.0;
<a name="l00322"></a>00322      <span class="keywordtype">double</span>       temp, tut1;
<a name="l00323"></a>00323 
<a name="l00324"></a>00324      tut1 = (jdut1 - 2451545.0) / 36525.0;
<a name="l00325"></a>00325      temp = -6.2e-6* tut1 * tut1 * tut1 + 0.093104 * tut1 * tut1 +
<a name="l00326"></a>00326              (876600.0*3600 + 8640184.812866) * tut1 + 67310.54841;  <span class="comment">// sec</span>
<a name="l00327"></a>00327      temp = fmod(temp * deg2rad / 240.0, twopi); <span class="comment">//360/86400 = 1/240, to deg, to rad</span>
<a name="l00328"></a>00328 
<a name="l00329"></a>00329      <span class="comment">// ------------------------ check quadrants ---------------------</span>
<a name="l00330"></a>00330      <span class="keywordflow">if</span> (temp &lt; 0.0)
<a name="l00331"></a>00331          temp += twopi;
<a name="l00332"></a>00332 
<a name="l00333"></a>00333      <span class="keywordflow">return</span> temp;
<a name="l00334"></a>00334    }  <span class="comment">// end gstime</span>
<a name="l00335"></a>00335 
<a name="l00336"></a>00336 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generado el Tue May 22 09:43:43 2012 para sgp4oo por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>
